package org.liip.clickhouse.config;

import com.alibaba.druid.pool.DruidDataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;



@Configuration
public class DruidConfig {

    @Autowired
    private ChParam chParam;

    @Bean
    public DataSource dataSource() {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(chParam.getUrl());
        datasource.setDriverClassName(chParam.getDriverClassName());
        datasource.setInitialSize(chParam.getInitialSize());
        datasource.setMinIdle(chParam.getMinIdle());
        datasource.setMaxActive(chParam.getMaxActive());
        datasource.setMaxWait(chParam.getMaxWait());
        datasource.setUsername(chParam.getUsername());
        datasource.setPassword(chParam.getPassword());
        return datasource;
    }
}
